package com.eudon.design_pattern.behavioral.interpreter;

/**
 * @author eudon
 * @description OR表达式，处理"或者"逻辑
 * @date 2025/9/3
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class OrExpression implements RuleExpression {
    private RuleExpression leftExpression;
    private RuleExpression rightExpression;

    public OrExpression(RuleExpression leftExpression, RuleExpression rightExpression) {
        this.leftExpression = leftExpression;
        this.rightExpression = rightExpression;
    }

    @Override
    public boolean interpret(Context context) {
        // OR逻辑：任意一个表达式为true时就返回true
        return leftExpression.interpret(context) || rightExpression.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + leftExpression.toString() + " 或者 " + rightExpression.toString() + ")";
    }
}